package install

import (
	models2 "beergo/app/admin/models"
	"beergo/app/sys/models"
	"os/exec"
)

func init() {
}

func CreateUserAction() {
	user := new(models.User)
	user.Account = "admin"
	user.Password = "123123"
	user.Token = "1"
	user.Salt = "1234"
	user.Save()
}
func CreateMenuAction() {

	//创建访问权限
	AdminGroup := new(models2.AdminGroup)
	AdminGroup.Name = "超级管理员"
	AdminGroup.Save()

	admin := new(models2.AdminUser)
	admin.Name = "admin"
	admin.Groups = []*models2.AdminGroup{{Id: 1}}
	admin.Token = "1"
	admin.Salt = "1234"
	admin.Uid = 1
	admin.Save()

	o1 := admin.GetOrm()
	m2mQs1 := o1.QueryM2M(admin, "Groups")
	m2mQs1.Add(AdminGroup)

	root := new(models2.AdminMenu)
	root.Name = "系统"
	root.Sort = "9999999"
	root.Save()

	menu := new(models2.AdminMenu)
	menu.Parent = root
	menu.Name = "菜单"
	menu.Url = "/admin/admin/AdminMenu/list"
	menu.Save()
	menu1 := new(models2.AdminMenu)
	menu1.Parent = root
	menu1.Name = "角色"
	menu1.Url = "/admin/admin/AdminGroup/list"
	menu1.Save()
	menu2 := new(models2.AdminMenu)
	menu2.Parent = root
	menu2.Name = "用户"
	menu2.Url = "/admin/admin/AdminUser/list"
	menu2.Save()
	o := AdminGroup.GetOrm()
	m2mQs := o.QueryM2M(AdminGroup, "Menus")
	//m2mQs.Clear()
	m2mQs.Add(menu)
	m2mQs.Add(menu1)
	m2mQs.Add(menu2)
}

func CreateTable() {
	//go run plugins/console/orm_command.go orm syncdb
	cmd := exec.Command("go", "run", "plugins/console/orm_command.go", "orm", "syncdb")
	cmd.Run()
}
